﻿using System;
using System.Application;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Ubiquity.Core.Extend;
using Ubiquity.Core.Web;
using Ubiquity.Web.Filters;

namespace Ubiquity.Web.Areas.SystemManage.Controllers
{
    /// <summary>
    ///用户操作日志 控制器 
    /// </summary>	
    [Area("SystemManage")]
    public class SysOperationLogController : BaseController
    {
        private readonly SysOperationLogService _service;
        private readonly SysModuleService _moduleService;
        private readonly SysModuleAuthorizeService _moduleAuthorizeService;
        public SysOperationLogController(SysOperationLogService service, SysModuleService moduleService, SysModuleAuthorizeService moduleAuthorizeService)
        {
            _service = service;
            _moduleService = moduleService;
            _moduleAuthorizeService = moduleAuthorizeService; 
        }

        [HttpGet]
        [Authorize]

        public ActionResult GetGridPaginationJson(WebPagination pagination, string userId, string start, string end)
        {
            DateTime startDate = Convert.ToDateTime(Validate.IsDate(start) ? start : "1979-01-01");
            DateTime endDate = Validate.IsDate(end) ? Convert.ToDateTime(end) : DateTime.Now;
            var paging = pagination.Change();
            var data = new
            {
                rows = _service.GetList(paging, userId, startDate, endDate.AddDays(1)),
                total = paging.Total,
                page = paging.Page + 1,
                records = paging.Records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        public ActionResult GetModuleDictionaryJson()
        {
            var moduleData = _moduleService.GetList();
            var authorizeData = _moduleAuthorizeService.GetList();
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            foreach (var item in moduleData)
            {
                var fieldItem = new
                {
                    item.FullName
                };
                dictionary.Add(item.Id, fieldItem);
            }
            foreach (var item in authorizeData)
            {
                var fieldItem = new
                {
                    item.FullName
                };
                dictionary.Add(item.Id, fieldItem);
            }
            return Content(dictionary.ToJson());
        }
        //ar roleId = OperatorProvider.Provider.GetCurrently(LoginManage.GetLoginId()).RoleId;
        //var data = _roleAuthorizeService.GetButtonList(roleId);

        //[HttpPost]
        //
        //[HandlerAuthorize]
        //[ValidateAntiForgeryToken]
        //public ActionResult Insert(SysOperationLogEntity entity, string keyValue)
        //{
        //    return _app.Insert(entity) ? Success("操作成功。") : Error("操作失败。");
        //} 
        //[HttpPost]
        //
        //[HandlerAuthorize]
        //[ValidateAntiForgeryToken]
        //public ActionResult DeleteForm(string keyValue)
        //{
        //    return _app.Delete(keyValue) ? Success("操作成功。") : Error("操作失败。");
        //}
    }

}